#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1010;
int n, m;
int st[N][N];
int g[N][N];
int res;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
void dfs(int x, int y)
{
	st[x][y] = 1;
	res++;
	for (int i = 0; i < 4; i++) {
		int a = dx[i] + x;
		int b = dy[i] + y;
		if (a <= 0 || a > n || b > m || b <= 0)continue;
		if (st[a][b] || !g[a][b])continue;
		dfs(a, b);
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> g[i][j];
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (!st[i][j] && g[i][j]) {
				res = 0;
				dfs(i, j);
				ans = max(res, ans);
			}
		}
	}
	cout << ans << endl;
	return 0;
}